using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using THSLib;using THSERP.BaseProvider;
using DevExpress.XtraGrid.Views.Grid;
using System.Windows.Forms;

namespace THSERP.Modules.CompanyConstant
{
    public partial class ProductTypeGridControl : THSGridControl
    {
        public override void InitGridControlDataSource()
        {
            base.InitGridControlDataSource();
            ADConfigValuesController objConfigValuesController = new ADConfigValuesController();
            DataSet ds = objConfigValuesController.GetADConfigValuesByGroup(ADConfigValueUtility.ADConfigValueProductType);
            this.DataSource = ds.Tables[0];
            this.RefreshDataSource();
        }

        protected override GridView InitializeGridView()
        {
            GridView gridView = new GridView();
            gridView.Columns.AddVisible("ADConfigText");
            gridView.OptionsView.ShowColumnHeaders = false;
            gridView.OptionsView.ShowGroupPanel = false;
            gridView.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            gridView.KeyUp += new System.Windows.Forms.KeyEventHandler(GridView_KeyUp);
            return gridView;
        }

        protected override void GridView_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            base.GridView_KeyUp(sender, e);

            GridView gridView = (GridView)sender;

            if (e.KeyCode == Keys.Delete)
            {
                DataView dataView = (DataView)gridView.DataSource;
                DataRow row = (DataRow)gridView.GetDataRow(gridView.FocusedRowHandle);
                if (row != null)
                    dataView.Table.Rows.Remove(row);
            }
            gridView.RefreshData();

        }
    }
}
